<?php
namespace App\Repositories;

use App\Models\OrderReserve;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use App\Models\Shop;
use App\Models\ShopRoomTable;
use App\Models\ShopDish;
use App\Models\ShopDishAttribute;
use App\Models\Order;
use App\Models\OrderInvitation;
//兼容小程序用到
use App\Models\WeixinUser;
use App\Models\UserCheck;
use App\Tools\Jpush;

class ReserveRepository
{

    //预定检查时间判断空房空桌
    public function checkDeskRoom($shop_id,$arrive_time){
        try{
            //商家判断
            $shop=Shop::where('is_check',1)->where('is_reserve',1)->find($shop_id);
            if(!$shop){
                return show(30001,"商铺不存在");
            }
            //时间判断1
            if(strtotime($arrive_time) < time()+15*60){
                return show(30001,"请提前15分钟预定");
            }
            //时间判断2
            $arrive_hi  = date("H:i",strtotime($arrive_time));  //预定的时间
            //商家信息
            $shopinfo = $shop->shopinfo;
            if(!$shopinfo){
                return show(30001,"商家信息错误");
            }else{
                $opentimes = array_filter(explode(',',$shopinfo->opentime));
                $isinopentime = false;
                foreach($opentimes as $k=>$v){
                    $opentime = explode('--',$v);
                    if(count($opentime)!=2){
                        return show(30001,"营业时间有误");
                    }else{
                        if(strtotime($opentime[0])<strtotime($arrive_hi) && strtotime($opentime[1])>strtotime($arrive_hi))
                        {
                            $isinopentime = true;
                        }
                    }
                }
                if($isinopentime == false){
                    return show(30001,"选取的时间不在营业时间内");
                }
            }
            //商家房桌
            $roomdesk = ShopRoomTable::where('shop_id',$shop_id)->get();
            if(count($roomdesk)==0){
                return show(30001,"该商家未开设房桌");
            }
            //预定订单
            $order = Order::where('shop_id',$shop_id)->where('order_type',1)->whereIn('order_status',[2,3])->with('rorder')->get();
            if(count($order)==0){
                return show(200,"获取成功",$roomdesk);
            }else{
                $orderreserve = [];
                foreach($order as $k=>$v){
                    if(strtotime($v->rorder->arrive_time)-$shopinfo->eating_time*3600<strtotime($arrive_time)&&
                      strtotime($arrive_time)<strtotime($v->rorder->arrive_time)+$shopinfo->eating_time*3600)
                    {
                        $orderreserve[$k] = $v->rorder;
                    }

                }
            }

            if(count($orderreserve) ==0){
                return show(200,"获取成功",$roomdesk);
            }else{
                $forbidenid ='';
                foreach($orderreserve as $v){
                    $forbidenid .=$v->desk_room.'|';
                }
                $forbidenid = array_filter(explode('|',$forbidenid));
                $roomdesk = ShopRoomTable::where('shop_id',$shop_id)->whereNotIn('id',$forbidenid)->get();
                if(count($roomdesk)==0){
                    return show(30001,"没有空房空桌");
                }else{
                    return show(200,"获取成功", $roomdesk);
                }
            }
       }catch (\Exception $e){
//            dd($e->getMessage());
            return show(30001,"系统繁忙，请稍后再试");
        }

    }

    //预定下单
    public function addOrder($cart){
        try{
            //模拟数据
            $arrive_time =$cart['arrive_time'];
            $shop_id     =$cart['shop_id'];
            //商家判断
            $shop=Shop::where('is_check',1)->where('is_reserve',1)->find($shop_id);
            if(!$shop){
                return show("30001","商铺不存在");
            }
            //时间判断2
            $arrive_hi  = date("H:i",strtotime($arrive_time));  //预定的时间
            //商家信息
            $shopinfo = $shop->shopinfo;
            if(!$shopinfo){
                return show(30001,"商家信息错误");
            }else{
                $opentimes = array_filter(explode(',',$shopinfo->opentime));
                $isinopentime = false;
                foreach($opentimes as $k=>$v){
                    $opentime = explode('--',$v);
                    if(count($opentime)!=2){
                        return show(30001,"营业时间有误");
                    }else{
                        if(strtotime($opentime[0])<strtotime($arrive_hi) && strtotime($opentime[1])>strtotime($arrive_hi))
                        {
                            $isinopentime = true;
                        }
                    }
                }
                if($isinopentime == false){
                    return show(30001,"选取的时间不在营业时间内");
                }
            }
            //商家房桌
            $roomdesk = ShopRoomTable::where('shop_id',$shop_id)->get();
            if(count($roomdesk)==0){
                return show(30001,"该商家未开设房桌");
            }
            //预定订单
            $order = Order::where('shop_id',$shop_id)->where('order_type',1)->whereIn('order_status',[2,3])->with('rorder')->get();
            if(count($order)!=0){
                $orderreserve = [];
                foreach($order as $k=>$v){
                    if(strtotime($v->rorder->arrive_time)-$shopinfo->eating_time*3600<strtotime($arrive_time)&&
                        strtotime($arrive_time)<strtotime($v->rorder->arrive_time)+$shopinfo->eating_time*3600)
                    {
                        $orderreserve[$k] = $v->rorder;
                    }

                }
                //判断是否被占用
                if(count($orderreserve)!=0){
                    $forbidenid ='';
                    foreach($orderreserve as $v){
                        $forbidenid .=$v->desk_room.'|';
                    }
                    $forbidenid = array_filter(explode('|',$forbidenid));
                    $chooseid =explode('|',$cart['desk_room']);
                    if(count(array_intersect($forbidenid,$chooseid))!=0){
                        return show("30001","选择的房间有被占用的");
                    }
                }
            }

            //验证价格(除非你有更好的方法否则别乱来)
            $top_amount=$top_price = 0;
            foreach($cart['dish'] as $k=>$v)
            {
                $dishes = ShopDish::find($v['dishes_id']);
                if($dishes){
                    $dishes =  $dishes->toArray();
                    if($dishes['is_attr']==1){
                        //获取数据库的规格计算
                        $ShopDishAttribute = ShopDishAttribute::where('dish_id',$dishes['id'])->get();
                        $spec_price = 0;
                        foreach($ShopDishAttribute as $k2=>$v2)
                        {
                            foreach(explode(',',$v2['spec']) as $k3=>$v3)
                            {
                                $spec = explode('|',$v3);
                                //获取购物车的规格计算
                                $cart_dish_spec = explode(',',$cart['dish'][$k]['spec']);
                                foreach($cart_dish_spec as $k4=>$v4){
                                    $cart_spec = explode('|',$v4);
                                    if($cart_spec[0]==$spec[0]){
                                        $spec_price += floatval($spec[1]);
                                    }

                                }

                            }

                        }
                        //（规格价+基础价）* 数量 * 折扣
                        $top_amount += ($spec_price+$dishes['price'])*$cart['dish'][$k]['goods_number']*$dishes['discount'];
                        $top_price  += ($spec_price+$dishes['price'])*$cart['dish'][$k]['goods_number'];
                    }else{
                        $top_amount += $dishes['price'] * $cart['dish'][$k]['goods_number']*$dishes['discount'];
                        $top_price  += $dishes['price'] * $cart['dish'][$k]['goods_number'];
                    }
                }
            }
            //强转防止溢出
            $top_amount = round($top_amount,2);
//            if($top_amount !=$cart['top_price']){
//                return show("30003","购物车异常！",["top_price" =>$top_amount]);
//            }
            //验证房桌最低消费
            $top_min_consumption = 0;
            foreach(explode('|',$cart['desk_room']) as $v){
                $ShopRoomTable=ShopRoomTable::find($v);
                $top_min_consumption += $ShopRoomTable->min_consumption;
            }
            //获取所需支付的金额
            if($top_min_consumption>$top_amount){//first
                $top_amount = $top_min_consumption;
            }else{//second
                //菜钱 * 收取额度百分比
                $top_amount =  $top_amount*$shop->shopinfo->gather_discount;
            }
            //生成订单
            $insert=Order::create([
                "user_id"=>Auth::id(),      //用户id
                "shop_id"=>$cart["shop_id"],//商铺id
                "order_type"=>1,            //预定
                "order_number"=>randID(),   //订单编号
                "order_status"=>1,          //订单状态
                "note"=>$cart['note'],      //订单备注
                "order_price"=>$top_price,  //订单总价
                "order_amount"=>$top_amount,//实际价格
                "product_type"=>1,          //餐饮模块（1）
            ]);
            //处理预定信息
            OrderReserve::create([
                "order_id"=>$insert['id'],            //订单id
                "desk_room"=>$cart['desk_room'],      //预定房桌
                "arrive_time"=>$cart['arrive_time'],  //到达时间
                "name"=>$cart['name'],                //姓名
                "phone"=>$cart['phone'],              //电话
            ]);
            //处理菜单详情
            foreach($cart['dish'] as $k=>$v){
                $cart['dish'][$k]['order_id']=$insert['id'];
                $cart['dish'][$k]['amount']  = $cart['dish'][$k]['sell_price']=$v['goods_number']*$v['price'];
            }
            DB::table('order_details')->insert($cart["dish"]);
            return show(200,"预定成功",["order_id"=>$insert['id'],"money"=>$top_amount,"order_type"=>1]);
        }catch (\Exception $e){
            dd($e->getMessage());
            //return show(30001,"系统繁忙，请稍后再试");
        }
    }

    // 小程序预定下单
    public function addProgramOrder($cart){
        try{
        $cart = $cart[0];
        //模拟数据
        $arrive_time =$cart['arrive_time'];
        $shop_id = $cart['shop_id'];
        //商家判断
        $shop=Shop::where('is_check',1)->where('is_reserve',1)->find($shop_id);
        if(!$shop){
            return show("30001","商铺不存在");
        }
        //时间判断2
        $arrive_hi  = date("H:i",strtotime($arrive_time));  //预定的时间
        //商家信息
        $shopinfo = $shop->shopinfo;
        if(!$shopinfo){
            return show(30001,"商家信息错误");
        }else{
            $opentimes = array_filter(explode(',',$shopinfo->opentime));
            $isinopentime = false;
            foreach($opentimes as $k=>$v){
                $opentime = explode('--',$v);
                if(count($opentime)!=2){
                    return show(30001,"营业时间有误");
                }else{
                    if(strtotime($opentime[0])<strtotime($arrive_hi) && strtotime($opentime[1])>strtotime($arrive_hi))
                    {
                        $isinopentime = true;
                    }
                }
            }
            if($isinopentime == false){
                return show(30001,"选取的时间不在营业时间内");
            }
        }
        //商家房桌
        $roomdesk = ShopRoomTable::where('shop_id',$shop_id)->get();
        if(count($roomdesk)==0){
            return show(30001,"该商家未开设房桌");
        }
        //预定订单
        $order = Order::where('shop_id',$shop_id)->where('order_type',1)->whereIn('order_status',[2,3])->with('rorder')->get();
        if(count($order)!=0){
            $orderreserve = [];
            foreach($order as $k=>$v){
                if(strtotime($v->rorder->arrive_time)-$shopinfo->eating_time*3600<strtotime($arrive_time)&&
                    strtotime($arrive_time)<strtotime($v->rorder->arrive_time)+$shopinfo->eating_time*3600)
                {
                    $orderreserve[$k] = $v->rorder;
                }
            }
            //判断是否被占用
            if(count($orderreserve)!=0){
                $forbidenid ='';
                foreach($orderreserve as $v){
                    $forbidenid .=$v->desk_room.'|';
                }
                $forbidenid = array_filter(explode('|',$forbidenid));
                $chooseid =explode('|',$cart['desk_room']);
                if(count(array_intersect($forbidenid,$chooseid))!=0){
                    return show("30001","选择的房间有被占用的");
                }
            }
        }

        //验证价格(除非你有更好的方法否则别乱来)
        $top_amount=$top_price = 0;
        foreach($cart['dish'] as $k=>$v)
        {
            $dishes = ShopDish::find($v['dishes_id']);
            if($dishes) {
                $dishes = $dishes->toArray();
                if ($dishes['is_attr'] == 1) {
                    //获取数据库的规格计算
                    $ShopDishAttribute = ShopDishAttribute::where('dish_id', $dishes['id'])->get();
                    $spec_price = 0;
                    foreach ($ShopDishAttribute as $k2 => $v2) {
                        foreach (explode(',', $v2['spec']) as $k3 => $v3) {
                            $spec = explode('|', $v3);
                            //获取购物车的规格计算
                            $cart_dish_spec = explode(',', $cart['dish'][$k]['spec']);
                            foreach ($cart_dish_spec as $k4 => $v4) {
                                $cart_spec = explode('|', $v4);
                                if ($cart_spec[0] == $spec[0]) {
                                    $spec_price += floatval($spec[1]);
                                }

                            }

                        }

                    }
                    //（规格价+基础价）* 数量 * 折扣
                    $top_amount += ($spec_price + $dishes['price']) * $cart['dish'][$k]['goods_number'] * $dishes['discount'];
                    $top_price += ($spec_price + $dishes['price']) * $cart['dish'][$k]['goods_number'];
                } else {
                    $top_amount += $dishes['price'] * $cart['dish'][$k]['goods_number'] * $dishes['discount'];
                    $top_price += $dishes['price'] * $cart['dish'][$k]['goods_number'];
                }
            }
        }
        //强转防止溢出
        $top_amount = round($top_amount,2);
//        if($top_amount !=$cart['top_price']){
//            return show("30003","购物车异常！",["top_price" =>$top_amount]);
//        }
        //验证房桌最低消费
        $top_min_consumption = 0;
        foreach(explode('|',$cart['desk_room']) as $v){
            $ShopRoomTable=ShopRoomTable::find($v);
            $top_min_consumption += $ShopRoomTable->min_consumption;
        }
        //获取所需支付的金额
        if($top_min_consumption>$top_amount){//first
            $top_amount = $top_min_consumption;
        }else{//second
            //菜钱 * 收取额度百分比
            $top_amount =  $top_amount*$shop->shopinfo->gather_discount;
        }
        $token = $cart['token'];
        $res = WeixinUser::where('token',$token)->first();
        if (!$res || $res->user_id == '0'){
            return show(202,'请绑定手机号');
        }
        $user_id = $res->user_id;
        //生成订单
        $insert=Order::create([
            "user_id"=>$user_id,//Auth::id(),      //用户id
            "shop_id"=>$cart["shop_id"],//商铺id
            "order_type"=>1,            //预定
            "order_number"=>randID(),   //订单编号
            "order_status"=>1,          //订单状态
            "note"=>$cart['note'],      //订单备注
            "order_price"=>$top_price,  //订单总价
            "order_amount"=>$top_amount,//实际价格
            "product_type"=>1,          //餐饮模块（1）
        ]);
        //处理预定信息
        OrderReserve::create([
            "order_id"=>$insert['id'],            //订单id
            "desk_room"=>$cart['desk_room'],      //预定房桌
            "arrive_time"=>$cart['arrive_time'],  //到达时间
            "name"=>$cart['name'],                //姓名
            "phone"=>$cart['phone'],              //电话
        ]);
        //处理菜单详情
        foreach($cart['dish'] as $k=>$v){
            $cart['dish'][$k]['order_id']=$insert['id'];
            $cart['dish'][$k]['amount']  = $v['goods_number']*$v['sell_price'];
        }
        DB::table('order_details')->insert($cart["dish"]);
        return show("200","预定成功",["order_id"=>$insert['id'],"money"=>$top_amount,"order_type"=>0]);
        }catch (\Exception $e){
            return show(30001,"系统繁忙，请稍后再试");
        }
    }

    //申请退款
    public function  applyForRefund($id,$token=false){
         //验证用户
         if($token){//token验证
             $WeixinUser = WeixinUser::where('token',$token)->first();
             if(!$WeixinUser){
                 return show(30001,"无效token！");
             }else{
                 $user= UserCheck::find($WeixinUser->user_id);
                 if(!$user){
                     return show(30001,"用户不存在！");
                 }
             }
             $user_id = $user->id;
         }else{//auth验证
             if(!Auth::id()){
                 return show(30001,'请先登录');
             }
             $user_id = Auth::id();
         }
         //验证订单
         $order = Order::where('order_type',1)->where('order_status',2)->find($id);
         if(!$order){
             return show(30001,'订单验证错误，不允许申请');
         }else{
             if($user_id != $order->user_id){
                 return show(30001,'没权限！');
             }
             $order->order_status = -1;
             $order->save();
             //通知商家
             return show(200,'申请成功，请耐心等待');
         }
    }

    //我已到店
    public function arrivaledShop($id,$token=false){
        //验证用户
        if($token){//token验证
            $WeixinUser = WeixinUser::where('token',$token)->first();
            if(!$WeixinUser){
                return show(30001,"无效token！");
            }else{
                $user= UserCheck::find($WeixinUser->user_id);
                if(!$user){
                    return show(30001,"用户不存在！");
                }
            }
            $user_id = $user->id;
        }else{//auth验证
            if(!Auth::id()){
                return show(30001,'请先登录');
            }
            $user_id = Auth::id();
        }

        //验证订单
        $order = Order::where('order_type',1)->find($id);
        if(!$order){
            return show(30001,'订单验证错误，订单不存在');
        }else{
            if($user_id != $order->user_id){
                return show(30001,'没权限！');
            }
            if($order->order_status == 2){
                $order->order_status = 3;
                $order->save();
                //通知商家
                return show(200,'选择到店成功');
            }else if($order->order_status == 3){
                return show(200,'您已选择到店，请勿重复提交');
            }else{
                return show(30001,'订单验证错误，不允许选择到店');
            }

        }
    }

    //服务员确定到店
    public function sureArrivaled($id,$token=false){
        if(!Auth::id()){
            return show(30001,'请先登录');
        }
        //确认人ID
        $user_id = Auth::id();
        //验证订单
        $order = Order::where('order_type',1)->find($id);
        if(!$order){
            return show(30001,'订单验证错误，订单不存在');
        }else{
            $Shop = Shop::find($order->shop_id);
            if(!$Shop){
                return show(30001,'订单验证错误，商家不存在');
            }
            if($user_id != $Shop->user_id){
                return show(30001,'没权限！');
            }
            if($order->order_status == 2){
                $order->order_status = 3;
                $order->save();
                //通知商家
                return show(200,'确定到店成功');
            }else if($order->order_status == 3){
                return show(200,'您已选择到店，请勿重复提交');
            }else{
                return show(30001,'订单验证错误，不允许选择到店');
            }

        }
    }
    //加菜
    public function addDishes($cart,$token=false){

        //验证用户
        if($token){//token验证
            $WeixinUser = WeixinUser::where('token',$token)->first();
            if(!$WeixinUser){
                return show(30001,"无效token！");
            }else{
                $user= UserCheck::find($WeixinUser->user_id);
                if(!$user){
                    return show(30001,"用户不存在！");
                }
            }
            $user_id = $user->id;
//            $cart = json_decode($cart,true);
        }else{//auth验证
            if(!Auth::id()){
                return show(30001,'请先登录');
            }
            $user_id = Auth::id();
        }

        //验证购物车
        $order = Order::where('order_type',1)->find($cart['order_id']);
        if(!$order){
            return show(30001,'订单验证错误，订单不存在');
        }else {
            if ($user_id != $order->user_id) {
                return show(30001, '没权限！');
            }
            if ($order->order_status != 3) {
                return show(30001, "当前订单状态不可加菜");
            }
            //计算价格
            $top_amount = $top_price = 0;
            foreach ($cart['dish'] as $k => $v) {
                $dishes = ShopDish::find($v['dishes_id']);
                if ($dishes) {
                    $dishes = $dishes->toArray();
                    if ($dishes['is_attr'] == 1) {
                        //获取数据库的规格计算
                        $ShopDishAttribute = ShopDishAttribute::where('dish_id', $dishes['id'])->get();
                        $spec_price = 0;
                        foreach ($ShopDishAttribute as $k2 => $v2) {
                            foreach (explode(',', $v2['spec']) as $k3 => $v3) {
                                $spec = explode('|', $v3);
                                //获取购物车的规格计算
                                $cart_dish_spec = explode(',', $cart['dish'][$k]['spec']);
                                foreach ($cart_dish_spec as $k4 => $v4) {
                                    $cart_spec = explode('|', $v4);
                                    if ($cart_spec[0] == $spec[0]) {
                                        $spec_price += floatval($spec[1]);
                                    }
                                }
                            }
                        }
                        //（规格价+基础价）* 数量 * 折扣
                        $top_amount += ($spec_price + $dishes['price']) * $cart['dish'][$k]['goods_number'] * $dishes['discount'];
                        $top_price += ($spec_price + $dishes['price']) * $cart['dish'][$k]['goods_number'];
                    } else {
                        $top_amount += $dishes['price'] * $cart['dish'][$k]['goods_number'] * $dishes['discount'];
                        $top_price += $dishes['price'] * $cart['dish'][$k]['goods_number'];
                    }

                }
                //强转防止溢出
                $top_amount = round($top_amount, 2);
                //更新订单
                $order->order_price = $order->order_price + $top_amount;
                $order->save();
                //添加菜式到订单
                foreach ($cart['dish'] as $k => $v) {
                    $cart['dish'][$k]['order_id'] = $cart['order_id'];
                    $cart['dish'][$k]['amount'] = $v['goods_number'] * $v['sell_price'];
                }
                DB::table('order_details')->insert($cart["dish"]);
                return show(200, '加菜成功');
            }
        }
    }

    //呼叫服务员
    public function callAttendant($id,$token=false){
        //验证用户
        if($token){//token验证
            $WeixinUser = WeixinUser::where('token',$token)->first();
            if(!$WeixinUser){
                return show(30001,"无效token！");
            }else{
                $user= UserCheck::find($WeixinUser->user_id);
                if(!$user){
                    return show(30001,"用户不存在！");
                }
            }
            $user_id = $user->id;
        }else{//auth验证
            if(!Auth::id()){
                return show(30001,'请先登录');
            }
            $user_id = Auth::id();
        }
        $order = Order::where('order_type',1)->where('order_status',3)->find($id);

        if(!$order){
            return show(30001,'订单验证错误，不允许呼叫');
        }else{
            if($user_id != $order->user_id){
                return show(30001,'没权限！');
            }
            //通知服务员
            $jpush = new Jpush();
            $jpush->callSmallTwo($id);
            return show('200','呼叫成功，请耐心等待');
        }
    }

    //生成邀请函
    public function buildInvitation($request){
//        dd($request);
        //验证用户
        if($request->token){//token验证
            $WeixinUser = WeixinUser::where('token',$request->token)->first();
            if(!$WeixinUser){
                return show(30001,"无效token！");
            }else{
                $user= UserCheck::find($WeixinUser->user_id);
                if(!$user){
                    return show(30001,"用户不存在！");
                }
            }
            $user_id = $user->id;
        }else{//auth验证
            if(!Auth::id()){
                return show(30001,'请先登录');
            }
            $user_id = Auth::id();
        }
        //验证传入参数
        if(!$request->order_id){
            return show(30002,"缺少参数订单ID！");
        }
        if(!$request->title){
            return show(30002,"缺少参数邀请标题！");
        }
        if(!$request->content){
            return show(30002,"缺少参数邀请内容！");
        }
        if(!$request->templet){
            $request->templet =0;
        }
        //验证订单
        $order = Order::find($request->order_id);
        if(!$order){
            return show(30003,"订单不存在！");
        }
        if($order->order_type!=1){
            return show(30003,"订单类型不支持！");
        }
        if($order->order_status!=2 && $order->order_status!=3){
            return show(30003,"订单状态不支持！");
        }
        if($user_id !=$order->user_id){
            return show(30003,"没有权限！");
        }
        //验证邀请
        if(OrderInvitation::where('order_id',$request->order_id)->first()){
            return show(30004,"已生成过邀请函！");
        }
        try{
            //生成邀请
            OrderInvitation::create([
                'title'   =>$request->title,
                'content' =>$request->content,
                'order_id'=>$request->order_id,
                'templet' =>$request->templet,
            ]);
            return show(200,"生成成功");
        }catch (\Exception $e){
//            dd($e->getMessage());
            return show(201,"邀请函生成失败");
        }

    }

    //显示邀请函
    public function showInvitation($request){
        //获取预定订单，显示邀请函
        //验证传入参数
        if(!$request->order_id){
            return show(30001,"缺少参数订单ID！");
        }
        //获取邀请函
        $invitation = OrderInvitation::where('order_id',$request->order_id)->first();
        if(empty($invitation)){
            return show(30001,"邀请函不存在！");
        }
        //验证订单
        $order = Order::find($request->order_id);

        if(!$order){
            return show(30001,"订单不存在！");
        }
        if($order->order_type!=1){
            return show(30001,"订单类型不支持！");
        }
        if($order->order_status!=2 && $order->order_status!=3){
            return show(30001,"邀请函已失效！");
        }
        //邀请函内容
        $invitation = ['id'=>$order->id,
                       'templet'=>$invitation->templet,
                       'invitation'=>$invitation,
                       'OrderDetail'=>$order->OrderDetail,
                       'OrderReserve'=>$order->orderReserve,
                       'Shop'=>$order->Shop,
                      ];
        return show(200,'获取成功',$invitation);
    }

//    //修改订单价格
//    public function changePrice($request){
//        //验证传入参数
//        if(!$request->order_id){
//            return show(30001,"缺少参数订单ID！");
//        }
//        //验证订单
//        $order = Order::find($request->order_id);
//        if(!$order){
//            return show(30001,"订单不存在！");
//        }
//        if($order->order_type!=1){
//            return show(30001,"订单类型不支持！");
//        }
//        if($order->order_status!=2 && $order->order_status!=3){
//            return show(30001,"订单状态验证失败，不予许修改！");
//        }
//        return show(200,'修改成功');
//    }


}
